"""
ForgeFed plugin for Pagure.
Copyright (C) 2020-2021 zPlus <zplus@peers.community>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, see <https://www.gnu.org/licenses/>.

# Notes

This module is kept empty because when the module forgefed.tasks is
imported by celery (when the queue worker is started), __init__.py is
also executed and we don't want to start a new Flask instance.
The entry point of the application is app.py.

We only set the logging options here because the "logging" module works
hierarchically. When we create a new log object using
logging.getLogger(__name__) the logger object is called
"forgefed.modulename" and will inherit its settings from the root
logger. So we set them here instead of in every single module.
https://docs.python.org/3/library/logging.html#logger-objects

SPDX-FileCopyrightText:  2020-2021 zPlus <zplus@peers.community>
SPDX-License-Identifier: GPL-2.0-only
"""

import logging
import os
from . import settings

if 'FORGEFED_WORKER' not in os.environ:
    print('The ForgeFed plugin needs to know if it has been started in a Celery worker thread.')
    print('You need to set the envvar FORGEFED_WORKER to "true" or "false"')
    exit()

log = logging.getLogger(__name__)
log.setLevel(settings.LOG_LEVEL)

# The app URL defined in the Pagure configuration, eg. "https://example.org/"
# We need this for generating absolute URIs in Activities.
import pagure.config
APP_URL = pagure.config.config['APP_URL'].rstrip('/')
assert APP_URL and len(APP_URL) > 0, 'APP_URL missing from Pagure configuration.'
